﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ForzaGT3.Common.Configuration;
using ForzaGT3.Models;
using Google.YouTube;
using Google.GData.Client;

namespace ForzaGT3.Helpers
{
    public class YoutubeVideoHelper
    {
       public static List<YoutubeVideoModel> GetVideos()
       {
           YouTubeRequestSettings settings =
           new YouTubeRequestSettings("ForzaGT3 Channel", SiteSettings.YoutubeDeveloperKey);
           YouTubeRequest request = new YouTubeRequest(settings);
           string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", SiteSettings.YoutubeChannel);
           
           Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));

           var data = (from video in videoFeed.Entries
                   select new YoutubeVideoModel()
                    {VideoId = video.VideoId, Title = video.Title}).ToList();

           return data;
       }

       public static IEnumerable<Video> GetVideoFeed()
       {
           YouTubeRequestSettings settings =
           new YouTubeRequestSettings("ForzaGT3 Channel", SiteSettings.YoutubeDeveloperKey);
           YouTubeRequest request = new YouTubeRequest(settings);
           string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", SiteSettings.YoutubeChannel);

           Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));

           return videoFeed.Entries;
       }
   
    }
}